/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.client.ui.symbiosys.platform;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.reliablesource.model.core.IReliableNode;
import org.reliablesource.symbiosys.platform.views.properties.tabbed.patientrecord.SymbiosysPropertySourceAdapter;

import com.patientis.model.patient.ViewPatientModel;

/**
 *
 * SymbiosysElementAdapterFactory.java<br>
 * Created on: Jun 26, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category factory, singleton
 * @see {@link IPropertySourceProvider}
 * @see {@link IAdapterFactory}
 * @since 1.0
 */
public class SymbiosysElementAdapterFactory implements IAdapterFactory,
    IPropertySourceProvider {
    static {
        instance = new SymbiosysElementAdapterFactory();
    }

    private static SymbiosysElementAdapterFactory instance;
    private final static Class<?>[] adapterList = {
            IPropertySource.class, IAdaptable.class
//            ,
//            IPropertySourceProvider.class
        };

    // singleton constructor
    private SymbiosysElementAdapterFactory() {
    }

    public static synchronized SymbiosysElementAdapterFactory getInstance() {
        return instance;
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
     *      java.lang.Class)
     */
    @SuppressWarnings("unchecked")
    public Object getAdapter(Object _adaptableObject, Class _adapterType) {
        Object _returnObject = null;

        if(_adapterType == IPropertySourceProvider.class){
            _returnObject = new SymbiosysPropertySourceAdapter((ViewPatientModel) ((IReliableNode) _adaptableObject).getModel());
        }
        
        else 
            if (_adaptableObject instanceof IReliableNode){
            _returnObject = new SymbiosysPropertySourceAdapter((ViewPatientModel) ((IReliableNode) _adaptableObject).getModel());
        }

        // else if (adaptableObject instanceof IReliableElement){
        // if(adapterType.getName().equals(IPropertySource.class.getName())){
        // if(elementAdapterMap.containsKey(String.valueOf(adaptableObject.hashCode())))
        // o =
        // elementAdapterMap.get(String.valueOf(adaptableObject.hashCode()));
        // else{
        // o = new ReliableElementPropertySourceAdapter((IReliableElement)
        // adaptableObject);
        // elementAdapterMap.put(String.valueOf(adaptableObject.hashCode()), o);
        // }
        // return o;
        // }
        return _returnObject;
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
     */
    public Class<?>[] getAdapterList() {
        return adapterList;
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.ui.views.properties.IPropertySourceProvider#getPropertySource(java.lang.Object)
     */
    public IPropertySource getPropertySource(Object object) {
	
	return new SymbiosysPropertySourceAdapter((ViewPatientModel) ((IReliableNode) object).getModel());
	
    }
}
